$(function () {
    //基础数据中时间切换监听器
    document.getElementById("goods-time-type").addEventListener("statistics-time",function (evt) {
        queryUVTopFiveGoodsList(evt.detail.type,evt.detail.startTime,evt.detail.endTime);
    });
    //初始化基础数据中的时间筛选
    initTimeType("goods-time-type");

    //初始化时间控件
    initTime("statTimeLaydate","endTimeLaydate",'goods-time-type');

    //商品统计接口
    queryGoodsProfileCountData();

    /**
     * 商品统计接口
     */
    function queryGoodsProfileCountData() {
        $.ajax({
            url: baseloaction + '/admin/stat/queryGoodsProfileCountData',
            type:'post',
            dataType:'json',
            beforeSend:function(XH){
                $("#goods-stat-loading-box").removeClass("hide");
                return true;
            },
            success:function (result) {
                if(result.success==true){
                    //在售商品
                    var sellGoodsCount = result.sellGoodsCount;
                    if(sellGoodsCount <=0){
                        $("#sell-goods-count").text('--');
                    }else{
                        $("#sell-goods-count").text(sellGoodsCount);
                    }
                    //总商品数
                    var goodsSum = result.goodsSum;
                    if(goodsSum <=0){
                        $("#goods-sum").text('--');
                    }else{
                        $("#goods-sum").text(goodsSum);
                    }
                    //录播课
                    var videoNum = result.courseSumCountMap.videoNum
                    if(videoNum <= 0){
                        $("#video-num").text('--');
                    }else{
                        $("#video-num").text(videoNum);
                    }
                    //套餐课
                    var packageNum = result.courseSumCountMap.packageNum;
                    if(packageNum <= 0){
                        $("#package-num").text('--');
                    }else{
                        $("#package-num").text(packageNum);
                    }
                    //会员课
                    var memberCourseNum = result.courseSumCountMap.memberCourseNum;
                    if(memberCourseNum <= 0){
                        $("#member-course-num").text('--');
                    }else{
                        $("#member-course-num").text(memberCourseNum);
                    }
                    //专栏课
                    var columnsNum = result.courseSumCountMap.columnsNum;
                    if(columnsNum <= 0){
                        $("#columns-num").text('--');
                    }else{
                        $("#columns-num").text(columnsNum);
                    }
                    //图书
                    var sellBookNum = result.bookSumCountMap.sellBookNum;
                    if(sellBookNum <= 0){
                        $("#sell-book-num").text('--');
                    }else{
                        $("#sell-book-num").text(sellBookNum);
                    }
                    //直播课
                    var liveNum = result.courseSumCountMap.liveNum;
                    if(liveNum <= 0){
                        $("#live-num").text('--');
                    }else{
                        $("#live-num").text(liveNum);
                    }
//直播课
                    var smallClassNum = result.courseSumCountMap.smallClassNum;
                    if(smallClassNum <= 0){
                        $("#small-class-num").text('--');
                    }else{
                        $("#small-class-num").text(smallClassNum);
                    }
                    //免费直播
                    var sellCourseOpenNum = result.courseOpenSumCountMap.sellCourseOpenNum;
                    if(sellCourseOpenNum <= 0){
                        $("#sell-course-open-num").text('--');
                    }else{
                        $("#sell-course-open-num").text(sellCourseOpenNum);
                    }
                    //讲师
                    var teacherCount = result.teacherCount;
                    if(teacherCount <= 0){
                        $("#teacher-count").text('--');
                    }else{
                        $("#teacher-count").text(teacherCount);
                    }
                    //班级
                    var classCount = result.classCount;
                    if(classCount <= 0){
                        $("#class-count").text('--');
                    }else{
                        $("#class-count").text(classCount);
                    }
                    //话题
                    var classTopicCount = result.classTopicCount;
                    if(classTopicCount <= 0){
                        $("#class-topic-count").text('--');
                    }else{
                        $("#class-topic-count").text(classTopicCount);
                    }
                    //付费问答
                    var yesChargeQaNum = result.qaSumCountMap.yesChargeQaNum;
                    if(yesChargeQaNum <= 0){
                        $("#yes-charge-qa-num").text('--');
                    }else{
                        $("#yes-charge-qa-num").text(yesChargeQaNum);
                    }
                    //免费问答
                    var yesFreeQaNum = result.qaSumCountMap.yesFreeQaNum;
                    if(yesFreeQaNum <= 0){
                        $("#yes-free-qa-num").text('--');
                    }else{
                        $("#yes-free-qa-num").text(yesFreeQaNum);
                    }
                }
                setTimeout(function () {
                   $("#goods-stat-loading-box").addClass("hide");
                },300);

                //访客榜 TOP5 之 商品
                queryUVTopFiveGoodsList(2,null,null);
            }
        });
    }

    /**
     * 访客榜 TOP5 之 商品
     * @param type
     * @param startTime
     * @param endTime
     */
    function queryUVTopFiveGoodsList(type,startTime,endTime) {
        $.ajax({
            url: baseloaction + '/admin/stat/queryUVTopFiveGoodsList',
            type:'post',
            dataType:'html',
            beforeSend:function(XH){
                $("#goods-ranking-box").removeClass("hide");
                return true;
            },
            data:{
                'type':type,
                'startTime':startTime,
                'endTime':endTime
            },
            success:function (result) {
                $("#top-fiv-shop-box").html(result);
                queryGoodsPayTopFiveList(type,startTime,endTime);
            }
        });
    }

    /**
     * 支付榜 TOP5 之 付费商品
     * @param type
     * @param startTime
     * @param endTime
     */
    function queryGoodsPayTopFiveList(type,startTime,endTime) {
        $.ajax({
            url: baseloaction + '/admin/stat/queryGoodsPayTopFiveList',
            type:'post',
            dataType:'html',
            data:{
                'type':type,
                'startTime':startTime,
                'endTime':endTime
            },
            success:function (result) {
                $("#pay-five-shop-box").html(result);
                querySubjectStudyRankingList(type,startTime,endTime);
            }
        });
    }



    /**
     * 学习榜 TOP7之 专业/科目
     * @param type
     * @param startTime
     * @param endTime
     */
    function querySubjectStudyRankingList(type,startTime,endTime) {
        $.ajax({
            url: baseloaction + '/admin/stat/querySubjectStudyRankingList',
            type:'post',
            dataType:'html',
            data:{
                'type':type,
                'startTime':startTime,
                'endTime':endTime
            },
            success:function (result) {
                $("#subject-stud-rnk-list-box").html(result);
                setTimeout(function () {
                    $("#goods-ranking-box").addClass("hide");
                },300);
            }
        });
    }
});